using System;
using System.IO;
using System.Web;
using Castle.MonoRail.Framework;

namespace KenEgozi.Com.Weblog.Application
{
	public class SimpleLog
	{
		public static void Syndication(IRailsEngineContext context, string message)
		{
			Syndication(context.Request.RawUrl,context.UnderlyingContext.Request.UserHostAddress,context.UrlReferrer, context.UnderlyingContext.Server, message);
		}

		public static void Syndication(HttpContext context, string message)
		{
			Syndication(context.Request.RawUrl, context.Request.UserHostAddress, "", context.Server, message);
		}

		private static void Syndication(string requestedUrl, string clientIP, string referrer, HttpServerUtility server, string message)
		{
			try
			{
				string path = server.MapPath("~/Content/Binary/SyndicationLog.txt");

				File.AppendAllText(path, string.Format(@"
At:[{0}]
RequestedUrl:[{1}]
UserHostAddress:[{2}]
Refferer:[{3}]
Message:[{4}]",
													   DateTime.Now.ToUniversalTime(),
													   requestedUrl,
													   clientIP,
													   referrer,
													   message ?? ""));
			}
			catch
			{
			}
		}

	}
}
